/**
 * Copyright (c) 2014 http://www.jieqianhua.com
 * //@ComponentScan(basePackages = "com.hualala.**")
 * @author xiyong.lxy
 * @date 2021.06.29
 */
package com.hllxd;


import io.undertow.Undertow;
import io.undertow.UndertowOptions;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.xnio.Options;

@SpringBootApplication
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

    private static final Integer TIMEOUT = 30*60*1000;

    @Bean
    public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
        UndertowEmbeddedServletContainerFactory factory =
                new UndertowEmbeddedServletContainerFactory();
        factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
            @Override
            public void customize(Undertow.Builder builder) {
                builder.setSocketOption(UndertowOptions.IDLE_TIMEOUT, TIMEOUT)
                        .setSocketOption(Options.REUSE_ADDRESSES, true)
                        .setSocketOption(Options.READ_TIMEOUT, TIMEOUT)
                        .setSocketOption(Options.WRITE_TIMEOUT, TIMEOUT)
                        .setSocketOption(Options.KEEP_ALIVE, true);
            }
        });
        return factory;
    }

}
